<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>Weather</title>
    <meta content="" name="descriptison">
    <meta content="" name="keywords">

    <script src="https://fastly.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script src="https://fastly.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js"></script>

    <!-- Favicons -->
    <link href="static/assets/img/favicon.png" rel="icon">
    <link href="static/assets/img/apple-touch-icon.png" rel="apple-touch-icon">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,600,600i,700,700i,900"
          rel="stylesheet">

    <!-- Vendor CSS Files -->
    <link href="static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/assets/vendor/icofont/icofont.min.css" rel="stylesheet">
    <link href="static/assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
    <link href="static/assets/vendor/animate.css/animate.min.css" rel="stylesheet">
    <link href="static/assets/vendor/venobox/venobox.css" rel="stylesheet">
    <link href="static/assets/vendor/aos/aos.css" rel="stylesheet">

    <!-- Template Main CSS File -->
    <link href="static/assets/css/style.css" rel="stylesheet">

</head>

<body>


<!-- ======= Header ======= -->
<header id="header">
    <div class="container">

        <div class="logo float-left">
            <h1 class="text-light"><a href="/index"><span>天气可视化系统的设计与实现</span></a></h1>
        </div>

        <nav class="nav-menu float-right d-none d-lg-block">
            <ul>
                <li><a href="/index">首页<i class="la la-angle-down"></i></a></li>

                <li class="drop-down"><a href="">可视化</a>
                    <ul>
                        <li><a href="/line">温度折线图</a></li>
                        <li class="active"><a href="/bar">天气柱状图</a></li>
                        <li><a href="/rose_pie">风力风向玫瑰图</a></li>
                        <li><a href="/pie">空气质量指数饼图</a></li>
                    </ul>
                </li>
                <li><a href="/data">数据展示</a></li>
                <li><a href="/weather">实时天气</a></li>
                <li><a href="/user_login">退出</a></li>
            </ul>
        </nav>

    </div>
</header><!-- End Header -->


<section class="about" id="about">
    <div class="">
        <!--  下拉框  -->
        <div class="container mt-5">
            <h3 style="text-align: center;">天气情况查询</h3>
            <form id="query-form">
                <div class="form-row align-items-end">
                    <div class="form-group col-md-3">
                        <label for="city">城市:</label>
                        <select class="form-control" id="city">
                            <option value="潼南">潼南</option>
                            <option value="合川">合川</option>
                            <option value="渝北">渝北</option>
                            <option value="巴南">巴南</option>
                        </select>
                    </div>
                    <div class="form-group col-md-3">
                        <label for="year">年份:</label>
                        <select class="form-control" id="year">
                            <!-- Options from 2016 to 2023 -->
                            {% for year in range(2016, 2024) %}
                                <option value="{{ year }}">{{ year }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group col-md-3">
                        <label for="month">月份:</label>
                        <select class="form-control" id="month">
                            <!-- Options from 1 to 12 -->
                            {% for month in range(1, 13) %}
                                <option value="{{ month }}">{{ month }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group col-md-3" style="text-align: center;">
                        <button type="submit" class="btn btn-primary">查询</button>
                    </div>
                </div>
            </form>
            <div id="weather-chart" style="width: 100%; height: 600px;" class="mt-5"></div>
        </div>
        <!--  Echarts  -->
        <script type="text/javascript">
            $(document).ready(function () {
                $('#query-form').on('submit', function (e) {
                    e.preventDefault();
                    var city = $('#city').val();
                    var year = $('#year').val();
                    var month = $('#month').val();

                    $.ajax({
                        url: "/get_data",
                        type: "GET",
                        data: {
                            city: city,
                            year: year,
                            month: month
                        },
                        success: function (data) {
                            var chartDom = document.getElementById('weather-chart');
                            var myChart = echarts.init(chartDom);
                            var option;

                            option = {
                                title: {
                                    text: data.title
                                },
                                tooltip: {
                                    trigger: 'axis'
                                },
                                xAxis: {
                                    type: 'category',
                                    data: data.weather_types
                                },
                                yAxis: {
                                    type: 'value'
                                },
                                series: [
                                    {
                                        name: '天数',
                                        type: 'bar',
                                        data: data.weather_counts
                                    }
                                ]
                            };

                            option && myChart.setOption(option);
                        }
                    });
                });
            });
        </script>
    </div>
</section>

<footer id="footer">
    <div class="container">
        <div class="copyright">Copyright &copy; 2021.数据科学与大数据技术.<a target="_blank" href="#">天气可视化系统</a>
        </div>
        <div class="credits"></div>
    </div>
</footer>

<!-- ======= Back to top Header ======= -->
<a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>

<!-- Vendor JS Files -->
<script src="static/assets/vendor/jquery/jquery.min.js"></script>
<script src="static/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="static/assets/vendor/jquery.easing/jquery.easing.min.js"></script>
<script src="static/assets/vendor/jquery-sticky/jquery.sticky.js"></script>
<script src="static/assets/vendor/venobox/venobox.min.js"></script>
<script src="static/assets/vendor/waypoints/jquery.waypoints.min.js"></script>
<script src="static/assets/vendor/counterup/counterup.min.js"></script>
<script src="static/assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
<script src="static/assets/vendor/aos/aos.js"></script>

<!-- Template Main JS File -->
<script src="static/assets/js/main.js"></script>

</body>

</html>